package cn.piesat.controller;

import cn.piesat.dto.PiesatUserLogDTO;
import cn.piesat.service.intf.UserLogService;
import cn.piesat.util.ResponseWrapperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 日志相关接口
 */
@RestController
@RequestMapping("log")
public class PiesatUserLogController {

    @Autowired
    private UserLogService userLogService;

    /**
     * 按日志类型  时间倒序 分页查询日志列表
     * logType 日志类型 0登录 1操作
     * @return
     */
    @GetMapping("list")
    public String listLog(Integer pageNum, Integer pageSize, PiesatUserLogDTO logDTO){
        if (pageNum < 0){
            pageNum = 0;
        }
        if (pageSize < 0){
            pageSize = 7;
        }
        Map<String, Object> resultMap = userLogService.listLog(pageNum, pageSize, logDTO);
        return ResponseWrapperUtil.executeResultMap(resultMap);
    }

    @GetMapping("loginChart")
    public String loginChart() {
        Map<String, Object> loginChartData = userLogService.getLoginChartData();
        return ResponseWrapperUtil.executeResultMap(loginChartData);
    }

    @GetMapping("busiChart")
    public String busiChart() {
        Map<String, Object> busiChartData = userLogService.getBusiChartData();
        return ResponseWrapperUtil.executeResultMap(busiChartData);
    }
}
